\bigskip
\bigskip
{\magonebf  2.3 Real-Valued Vectors (vector)}

An instance of the data type $vector$ is a vector of real variables.

\def\name{$vector$}
\def\type{$vector$}

\bigskip
{\bf 1. Creation}

a) \create v (int\ d)

b) \create v (double\ a,\ double\ b)

c) \create v (double\ a,\ double\ b,\ double\ c)
 

creates an instance $v$ of type $vector$; $v$ is initialized to the zero
vector of dimension $d$ (variant a), the two-dimensional vector $(a,b)$
(variant b) or the three-dimensional vector $(a,b,c)$ (variant c).


\bigskip
{\bf 2. Operations on a vector v}

\medskip
\+\cleartabs & \hskip 2.5truecm & \hskip 5truecm &\cr
\+\op int   dim {}         
                           {returns the dimension of $v$.}
\smallskip
\+\op double  length {}      
                           {returns the Euclidean length of $v$}
\smallskip
\+\op double  angle {vector\ w}  
                           { returns the angle between $v$ and $w$.}
\medskip
\+\opa double\&  {int\ i}           
                           {returns $i$-th component of $v$.}
\+\nop                     {\precond $0\le i \le v$.dim()$-$1.}
\smallskip
\+\opb vector       +  {v_1}
                           {Addition}
\+\nop                     {\precond $v$.dim() = $v_1$.dim().}
\smallskip
\+\opb vector    -  {v_1}
                           {Subtraction}
\+\nop                     {\precond $v$.dim() = $v_1$.dim().}
\smallskip
\+\opb double      *  {v_1}
                           {Scalar multiplication}
\+\nop                     {\precond $v$.dim() = $v_1$.dim().}
\smallskip
\+\opb vector    *  {r}
                           {Componentwise multiplication with double $r$}
\smallskip
\+\opb bool      == {v_1}
                           {Test for equality}
\smallskip
\+\opb bool      != {v_1}
                           {Test for inequality}
\medskip
\+\ops ostream\& << {O}  
                           {writes $v$ componentwise to the output stream $O$}
\smallskip
\+\ops istream\& >> {I}  
                           {reads $v$ componentwise from the input stream $I$}


\bigskip
{\bf 3. Implementation }
\medskip
Vectors are implemented by arrays of real numbers. All operations on a
vector $v$ take time $O(v.dim())$, except of dim and $[\ ]$ which take constant
time. The space requirement is $O(v.dim())$.

